package com.hqyj.ctxp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hqyj.ctxp.pojo.Role;
import com.hqyj.ctxp.pojo.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @className: UserMapper
 * @description: TODO 类描述
 * @author: mmm
 * @date: 2022/11/27
 **/
@Repository
public interface UserMapper extends BaseMapper<User> {

    //用户登录
    @Select("select * from user where user_no = #{userNo} and user_pwd = #{userPwd}")
    @Results(id = "loginMap",value = {
            @Result(id = true,column = "user_id",property = "userId"),
            @Result(column = "user_no",property = "userNo"),
            @Result(column = "user_name",property = "userName"),
            @Result(column = "user_pwd",property = "userPwd"),
            @Result(column = "create_time",property = "createTime"),
            @Result(column = "update_time",property = "updateTime"),
            @Result(column = "user_fk_role",property = "role",
                    one = @One(select = "com.hqyj.ctxp.mapper.RoleMapper.selectById"))
    })
    User login(@Param("userNo")Integer userNo,@Param("userPwd")String userPwd);

    //用户列表
    Page<User> selectUserList(@Param("userName")String userName,@Param("page")Page<User> page);

    //角色列表
    @Select("select * from role")
    @Results(id = "roleMap",value = {
            @Result(id = true,column = "role_id",property = "roleId"),
            @Result(column = "role_name",property = "roleName"),
    })
    List<Role> selectRoles();

    //根据用户编号修改用户角色
    @Update("UPDATE USER SET user_fk_role = #{userFkRole} WHERE user_no = #{userNo}")
    Integer changeUserRoleByUserNo(@Param("userFkRole")Integer userFkRole,@Param("userNo")Integer userNo);

    //根据用户编号删除用户信息
    Integer deleteUserInfoByUserNo(Integer userNo);

    //新增用户同时在用户信息表增加该用户
    Integer insertUserInfo(String userName);

    //验证用户原始密码
    @Select("select user_pwd from user where user_name = #{userName} and user_pwd = #{userPwd}")
    String checkPwd(User user);

}
